package homework_java.shape;
abstract class GeometricObject implements Comparable<GeometricObject>{
    public double ares(){
        return 0;
    }
    public double perimeter(){
        return 0;
    }
    @Override
    public int compareTo(GeometricObject o)
    {
        if(this.ares()<o.ares())
            return -1;
        else if(this.ares()>o.ares())
            return 1;
        else
            return 0;
    }
}
 class InvalidrectangleException extends Exception{
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private double weight,high;
   public InvalidrectangleException (double w,double h){
       super();
       this.weight=w;
       this.high=h;
   }
   public double getweight(){
       return weight;
   }
   public double gethigh(){
       return high;
   }
}
class rectangle extends GeometricObject {
     double weight;
     double high;
     rectangle(){
     }
     @Override
     public double ares(){
        return this.weight*this.high;
     }
     @Override
     public double perimeter(){
         return (this.weight+this.high)*2;
     }
     @Override 
     public String toString(){
         return "矩形长："+this.weight+", 高："+this.high+", 面积："+this.ares()+", 周长："+this.perimeter();

     }
     public void setbian(double h,double w) throws InvalidrectangleException {
        if (h >= 0 && w>=0)
           {this.high = h;
            this.weight=w;}
       else
           throw new InvalidrectangleException(weight,high);
   }
} 
  class InvalidRadiusException extends Exception{
         /**
          *
          */
         private static final long serialVersionUID = 1L;
         private double radius;
        public InvalidRadiusException (double radius){
            super("Invalid radius" + radius);
            this.radius=radius;
        }
        public double getRadius(){
            return radius;
        }
     static class Round extends GeometricObject {
         int point1;
         int point2;
         double line;

         Round(int a, int b) {
             this.point1 = a;
             this.point2 = b;
         }

         @Override
         public double ares() {
             return Math.PI * line * line;
         }
     
         @Override
         public double perimeter() {
             return Math.PI * line * 2;
         }

         @Override
         public String toString() {
             return "圆心：（" + this.point1 + "," + this.point2 + ")," + "面积" + this.ares() + ", 周长："
                     + this.perimeter();
         }

         public void setRadius(double newRadius) throws InvalidRadiusException {
             if (newRadius >= 0)
                 line = newRadius;
            else
                throw new InvalidRadiusException(newRadius);
        }
        
     }
     public static  class InvalidtriangleException extends Exception{
        /**
         *
         */
        private static final long serialVersionUID = 1L;
        private double a,b,c;
       public InvalidtriangleException (double d,double f,double g){
           super();
           this.a=d;
           this.b=f;
           this.c=g;
       }
       public double geta(){
           return a;
       }
       public double getb(){
           return b;
       }
       public double getc(){
        return c;
    }
     static class triangle extends GeometricObject{
         double a;
         double b;
         double c;
         triangle(){
         }
         @Override
         public double perimeter(){
             return  a+b+c;
         }
         @Override 
         public String toString(){
             return "三角形：边长分别为："+a+","+b+","+c+", 周长："+this.perimeter();
         }
         public void sets(double f,double g,double q) throws InvalidtriangleException {
            if ((f+g>q)&&(f+q>g)&&(g+q>f)){
                a=f;
                b=g;
                c=q;

            }     
           else
               throw new InvalidtriangleException(a,b,c);
       }
     
     }

     public static class DrawingGraphics {
         public static void main(String[] args) throws InvalidRadiusException, InvalidrectangleException {
             try {
                 rectangle r = new rectangle();
                 r.setbian(3, 5);
                 System.out.println(r.toString());
             } catch (InvalidrectangleException e) {
                 System.out.println("The invalid  is" + e.gethigh() + "," + e.getweight());
             }
             try {
                 Round rou = new Round(4, 5);
                 rou.setRadius(7);
                 System.out.println(rou.toString());
             } catch (InvalidRadiusException e) {
                 System.out.println("The invalid radiud is" + e.getRadius());
             }
             try {
                 triangle t = new triangle();
                 t.sets(3, 4, 5);
                 System.out.println(t.toString());
             } catch (InvalidtriangleException e) {
                 System.out.println("The invalid 边长 is" + e.geta() + "," + e.getb() + "," + e.getc());
             }
         }
     }
    
    }
}
